class Solution {
public:
    vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {
        unordered_map<string,int>nmp;
        vector<string> ans;
        if(list1.size()==0 || list2.size()==0){return ans;}
        for(int i=0;i<list1.size();i++){
            nmp[list1[i]]=i;
        }
        int tmp=INT_MAX;
        for(int i=0;i<list2.size();i++){
            if(nmp.find(list2[i])==nmp.end()){continue;}
            if(nmp[list2[i]]+i<tmp){
                ans.clear();
                ans.push_back(list2[i]);
                tmp=nmp[list2[i]]+i;
            }
            else if(nmp[list2[i]]+i==tmp){
                ans.push_back(list2[i]);
            }
        }
        return ans;
    }
};